(function () {
    "use strict"
    /*数据共享区*/
    const _data = function () {
        return {
            title: '这是标题数据'
        }
    }
    function stopDefault(e) {
        e.preventDefault()
    }
    let data = new _data();
    $("#test").click(function () {
        console.log(data.title = 0, data.title)
    });
    /* 初始化轮播 */
    $("#l-slide").owlCarousel({
        loop: true,
        speed: 300,
        nav: true,
        dots: false,
        lazyLoad: true,
        autoplay: true,
        autoplayHoverPause: true,
        mouseDrag: true,
        items: 1
    });
    // 会场分类链接
    function getType() {
        const data = {
            left: [
                {
                    href: '#',
                    src: 'https://cdnimg.chinagoods.com/png/2021/12/07/f403dcd7edbc6d8481b562a54e70df36.png?imageMogr2/thumbnail/460x308/pad/1/color/#FFF',
                    title: '链接'
                }, {
                    href: '#',
                    src: 'https://cdnimg.chinagoods.com/jpg/2021/12/13/8a66849da6239f2afc53dea08e3e67e3.jpg?imageMogr2/thumbnail/460x308/pad/1/color/#FFF',
                    title: '链接'
                }
            ],
            right: [
                {
                    'data-id': 'hif86d867fcd86as8d6as8',
                    href: '#',
                    src: 'https://cbu01.alicdn.com/img/ibank/2020/613/458/16583854316_1361256684.400x400.jpg?imageMogr2/thumbnail/160x160/pad/1/color/#FFF',
                    title: '无',
                    price:30
                }
            ]
        }
        let $type = $(".type-left"), $slide = $(".type-right-slide>.type-right-slide-warpper");
        data.left.forEach(el => {
            let $el = `<a  href='${el.href}' title='${el.title}'><img src='${el.src}'></a>`;
            $type.append($el);
        });

        /* delete */
        let c = data.right[0];
        for (let i = 0; i < 6; i++) {
            data.right[i] = c
        }
        // 复制数组
        let copy = data.right;
        data.right = data.right.concat(copy);

        data.right.forEach(el => {
            let $el = `<a href='${el.href}/data_id = ${el["data-id"]}'>
                <img src='${el.src}' alt=''/>
                <p>${el.title}</p>
            </a>`;
            $slide.append($el);
        });
        // 判断商品超过开启跑马灯效果
        if ($slide.width() > $slide.parent().width()) {
            $slide.attr(
                'style', '--width:-' + $slide.width() / 2 + 'px',
            ).addClass("move");
        }
        // 处理滚动条滑动效果
        const $bar = $(".scroll-bar>i");
        let _y = 0, per = 0;
        per = $bar.height() / $bar.parent().height();
        $bar.on("mousedown", function (e) {
            stopDefault(e);
            $slide.addClass("pasued")
            _y = getPositionY(e);
            $(document).on("mousemove", function (e) {
                stopDefault(e);
                vMove(e)
            });
        });
        function vMove(e) {
            let y= getPositionY(e)
            if (y > 0 && y < ($bar.parent().height()-$bar.height())) {
                $bar.css({
                    transition: 'all 0s',
                    transform: `translatey(${getPositionY(e)}px)`
                });
                $slide.css({
                    transition: 'all 0s',
                    transform: `translateX(-${getPositionY(e)/per}px)`
                })
            }
            
        }
        function getPositionY(e) {
            return e.clientY - $bar.parent()[0].getBoundingClientRect().top;
        }
        $(document).on("mouseup", function (e) {
            stopDefault(e);
            $(this).off("mousemove");
            $slide.removeClass("pasued")
        })
    }
    getType();
})()